<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>角色信息</title>
	<meta name="decorator" content="old"/>
</head>
<body>
	<%-- <ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/role/">角色列表</a></li>
		<li class="active"><a href="${ctx}/sys/role/assign?id=${role.id}"><shiro:hasPermission name="sys:role:edit">角色分配</shiro:hasPermission><shiro:lacksPermission name="sys:role:edit">人员列表</shiro:lacksPermission></a></li>
	</ul> --%>
	<div class="container-fluid breadcrumb">
		<div class="row-fluid span12">
			<span class="span4">角色名称: <b>${role.name}</b></span>
			<span class="span4">归属机构: ${role.office.name}</span>
			<span class="span4">英文名称: ${role.enname}</span>
		</div>
		<div class="row-fluid span8">
			<span class="span4">角色类型: ${role.roleType}</span>
			<c:set var="dictvalue" value="${role.dataScope}" scope="page" />
			<span class="span4">数据范围: ${fns:getDictLabel(dictvalue, 'sys_data_scope', '')}</span>
		</div>
	</div>
	<sys:message content="${message}"/>
	<form id="assignRoleForm" action="${ctx}/sys/role/assignrole" method="post" class="hide">
		<input type="hidden" name="id" value="${role.id}"/>
		<input id="idsArr" type="hidden" name="idsArr" value=""/>
	</form>
	<div class="btns">
		<button type="button" class="btn-custom" onclick="assign()">添加用户</button>
		<button type="button" class="btn-custom btndelete" data-deleteurl='${ctx}/sys/role/outrole'  onclick="top.$.jBox.confirm('真的要删除吗？','系统提示',del)">删除</button>
	</div>
	<div class="tbbox firsttdCenter">
		<div class="boxthead">
           <div class="autobox">
           		<table cellpadding="0" cellspacing="0" class="table table-bordered tbhead">
	              <thead>
              		<tr>
	                   <th style="width:30px;"><input type="checkbox" class="checkall"/></th>
	                   <th style="width:100px;">归属公司</th>
	                   <th style="width:100px;">归属部门</th>
	                   <th style="width:100px;">登录名</th>
	                   <th style="width:100px;">姓名</th>
	                   <th style="width:100px;">电话</th>
	                   <th style="width:100px;">手机</th>
	                </tr>
	              </thead>
	           </table>
           </div>
       </div>
	   <div class="boxbody ">
            <table cellpadding="0" cellspacing="0" class="table table-bordered tbbody">
                <tbody>
	                <c:forEach items="${userList}" var="user">
	                	<tr>
							<td style="width:30px;">
								<input type="checkbox" data-param="userId=${user.id}"/>
							</td>
		                    <td style="width:100px;">${user.company.name}</td>
							<td style="width:100px;">${user.office.name}</td>
							<td style="width:100px;">${user.loginName}</td>
							<td style="width:100px;">${user.name}</td>
							<td style="width:100px;">${user.phone}</td>
							<td style="width:100px;">${user.mobile}</td>
						</tr>
	                </c:forEach>
                </tbody>
            </table>
        </div>
	</div>
	<script type="text/javascript">
		function assign() {
			top.$.jBox.open("iframe:${ctx}/sys/role/usertorole?id=${role.id}", "添加用户",810,$(top.document).height()-240,{
				buttons:{"确定分配":"ok", "清除已选":"clear", "关闭":true}, bottomText:"通过选择部门，然后为列出的人员分配角色。",submit:function(v, h, f){
					var pre_ids = h.find("iframe")[0].contentWindow.pre_ids;
					var ids = h.find("iframe")[0].contentWindow.ids;
					//nodes = selectedTree.getSelectedNodes();
					if (v=="ok"){
						// 删除''的元素
						if(ids[0]==''){
							ids.shift();
							pre_ids.shift();
						}
						if(pre_ids.sort().toString() == ids.sort().toString()){
							top.$.jBox.tip("未给角色【${role.name}】分配新成员！", 'info');
							return false;
						};
				    	// 执行保存
				    	loading('正在提交，请稍等...');
				    	var idsArr = "";
				    	for (var i = 0; i<ids.length; i++) {
				    		idsArr = (idsArr + ids[i]) + (((i + 1)== ids.length) ? '':',');
				    	}
				    	$('#idsArr').val(idsArr);
				    	$('#assignRoleForm').submit();
				    	return true;
					} else if (v=="clear"){
						h.find("iframe")[0].contentWindow.clearAssign();
						return false;
	                }
				}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		}
		
		function del(v, h, f) {
			var checkboxs=$(".tbbody").find("input[type=checkbox]:checked");
			if(checkboxs.length>1){top.$.jBox.tip("不能多条数据同时修改",""); return false;}
			//if(checkboxs.length==0){top.$.jBox.tip("请选择一条修改的数据",""); return false;}
			if(v=="ok"){
				var param=$(".tbbody").find("input[type=checkbox]:checked").attr("data-param");
				var url=$(".btndelete").attr("data-deleteurl");
				window.location.href=url+"?roleId=${role.id}&"+param;
			}else{
				top.$.jBox.tip("删除失败","");
			}
		}
	</script>
</body>
</html>
